package homework8;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Random;

public class work5 {
	public static void main(String[] args) throws IOException{
		int lucky=66;
		
		FileInputStream fis=new FileInputStream("names.txt");
		BufferedReader br=new BufferedReader(new InputStreamReader(fis));
		ArrayList<String> arr=new ArrayList<String>();
		String s;
		while((s=br.readLine())!=null) {
			if(!s.isEmpty()) {
				String[] temp=s.split("-");
				arr.add(temp[0]);
			}
		}
		fis=new FileInputStream("store2.txt");
		br=new BufferedReader(new InputStreamReader(fis));
		int count=Integer.valueOf(br.readLine());
		br.close();
		Random r=new Random();
		while(true) {
			int a=r.nextInt(arr.size());
			if(count%3!=0&&a==lucky) {
			}
			else if(count%3==0) {
				System.out.println(arr.get(lucky));
				count++;
				break;
			}
			else {
				System.out.println(arr.get(a));
				count++;
				break;
			}
		}
		FileOutputStream fos=new FileOutputStream("store2.txt");
		BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(fos));
		bw.write(String.valueOf(count));
		bw.close();
	}
}
